package org.tlipoca.smarticletag.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.genntii.smcommon.result.Result;
import org.genntii.smdomain.doc.VO.ArticleTagDocVO;
import org.genntii.smdomain.dto.ArticleTagDTO;
import org.genntii.smdomain.vo.ArticleTagVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tlipoca.smarticletag.service.ArticleTagService;

import java.util.ArrayList;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/article_tag")
public class ArticleTagController {

    @Autowired
    private ArticleTagService articleTagService;

    @Operation(summary = "查询文章标签列表是否存在")
    @GetMapping("/exists")
    public Result<Boolean> articleTagListExists(@RequestParam("tagIds") ArrayList<Long> tagIds){
        return Result.success(articleTagService.articleTagListExistsService(tagIds));
    }

    @Operation(summary = "根据文章标签ID列表查询文章标签列表")
    @GetMapping("/tagIds")
    public Result<ArrayList<ArticleTagVO>> getArticleTagListByTagId(@RequestParam("tagIds") ArrayList<Long> tagIds) {
        return Result.success(articleTagService.getArticleTagListByTagId(tagIds));
    }

    @Operation(summary = "getArticleTagDocVOListByTagId")
    @GetMapping("/tagdocvo")
    public Result<ArrayList<ArticleTagDocVO>> getArticleTagDocVOLIstByTagId(@RequestParam("tagIds")ArrayList<Long> tagIds){
        return Result.success(articleTagService.getArticleTagDocVOListByTagId(tagIds));
    }

    @Operation(summary = "新增文章标签")
    @PostMapping
    public Result addArticleTag(@RequestBody ArticleTagDTO articleTagDTO) {
        articleTagService.addArticleTagService(articleTagDTO);
        return Result.success();
    }

    @Operation(summary = "删除文章标签")
    @DeleteMapping("/{tagId}")
    public Result deleteArticleTag(@PathVariable Long tagId) {
        articleTagService.deleteArticleTagService(tagId);
        return Result.success();
    }

    @Operation(summary = "更新文章标签")
    @PutMapping("/{tagId}")
    public Result updateArticleTag(@PathVariable Long tagId, @RequestBody ArticleTagDTO articleTagDTO) {
        articleTagService.updateArticleTagService(tagId, articleTagDTO);
        return Result.success();
    }

    //TODO 待测试
    @Operation(summary = "根据文章ID标签ID列表Map批量获取文章标签列表")
    @PostMapping("/batch")
    public Result<Map<String, ArrayList<ArticleTagVO>>> getArticleTagListByArticleTagMap(@RequestBody Map<String , ArrayList<Long>> articleTagMap) {
        return Result.success(articleTagService.getArticleTagListByArticleTagMapService(articleTagMap));
    }

    @GetMapping("/list")
    public Result<ArrayList<ArticleTagVO>> getArticleTagVOList(){
        return Result.success(articleTagService.getArticleTagList());
    }

}
